import axios from 'axios';

var qs = require('qs');

let basePath3 = '/api/v3.0/admin/api/';

/**
 * 路径  start
 * ----------------------------------------------------------------------------------------------------------------------
 */
const PRESSRELEASES = basePath3 + 'press_releases';

const PRESSRELEASE = basePath3 + 'press_release';

const PRESSRELEASE_DEL = basePath3 + 'press_release/';

const PLATFORM_ALL = basePath3 + 'platform_all';

// 获取新闻公告列表
export const searchPressRelease = params => {
  return axios.get(PRESSRELEASES, {params: params});
};

// 批量删除
export const batchpressReleaseDel = id => {
  return axios.delete(PRESSRELEASE_DEL + id.join(','));
};

// 创建/修改新闻公告
export const savePressRelease = (params) => {
  return axios.post(PRESSRELEASES, params);
};

// 根据ID，置顶新闻
export const modifyStick = (id) => {
  return axios.post(PRESSRELEASE, qs.stringify({id: id}));
};

// 获取本条新闻的附件详情
export const searchPressReleaseFileByPressReleaseId = (id) => {
  return axios.get(basePath3 + 'get_press_release_file_list?id=' + id);
};

// 平台用户界面获取全部平台用户对应的新闻
export const getAllPressRelease = (params) => {
  return axios.get(PLATFORM_ALL, {params: params});
};

// 为当前新闻添加一条阅读记录
export const addReadRecord = (id) => {
  return axios.post(basePath3 + 'add_press_release_read?id=' + id);
};

// 获取当前用户的阅读记录
export const getCurrentUserReadList = () => {
  return axios.get(basePath3 + 'get_press_release_read_by_user_id');
};

// 获取当前用户所有读过的新闻
export const getReadPressRelease = (params) => {
  return axios.get(basePath3 + 'get_read_press_release_by_current_user_id', {params: params});
};

// 获取当前用户所有未读过的新闻
export const getUnreadPressRelease = (params) => {
  return axios.get(basePath3 + 'get_unread_press_release_by_current_user_id', {params: params});
};

// 获取该条新闻详情
export const getCurrentPressRelease = (id) => {
  return axios.get(basePath3 + 'get_press_release_by_pressreleaseid?id=' + id);
};

// 获取该条新闻的所有评论
export const getCommentsByStatus = (params) => {
  return axios.get(basePath3 + 'get_press_release_comment_by_press_release_id', {params: params});
};

export const getCommentsContainReply = (params) => {
  return axios.get(basePath3 + 'get_press_release_comment_contain_reply_by_press_release_id', {params: params});
};

// 对一条评论进行状态变更（审核、撤销审核）
export const changeStatus = (id) => {
  return axios.post(basePath3 + 'change_press_release_comment_status', qs.stringify({id: id}));
};

// 回复一条评论
export const addNewComment = (params) => {
  return axios.post(basePath3 + 'answer_press_release_comment', params);
};

// 发表一条评论
export const userAaddNewComment = (params) => {
  return axios.post(basePath3 + 'add_press_release_comment', params);
};

// 删除一条二级评论
export const deleteCommentReply = (id) => {
  return axios.delete(basePath3 + 'delete_marketing_press_release_by_id?id=' + id);
};

// 点赞
export const addLike = (id) => {
  return axios.post(basePath3 + 'add_like_by_press_release_id?id=' + id);
};

// 查看当前用户是否点赞过本条新闻
export const findLikeOrUnlike = (id) => {
  return axios.get(basePath3 + 'find_like_or_unlike_by_user_id?id=' + id);
};
